define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template', 'backend/kuerp/utils/number', '/assets/addons/kuerp/layui/layui.js'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template, NumberUtil) {

    var Controller = {
        index: function () {


            layui.use(['table', 'upload', 'form'], function () {

                var formatThousands = NumberUtil.formatThousands;

                // const domain = 'https://erp.3caimans.com';
                const domain = ''; // 使用相对路径

                console.log(Config, '66666666');

                function fetchData() {
                    return new Promise((resolve, reject) => {
                        $.ajax({
                            url: domain + "/kuerp/datainfo/index",
                            type: "post",
                            data: { types: 1 },
                            contentType: "application/x-www-form-urlencoded",
                            dataType: "json",
                            success: function (res) {
                                resolve({ column: res.column, data: res.data });
                            },
                            error: function (err) {
                                reject(err);
                            }
                        });
                    });
                }

                async function main() {
                    try {
                        const res = await fetchData();
                        const achatscolumn = res.column;
                        const achatsdata = res.data;
                        var achatsChart = echarts.init(document.getElementById("achats-chart"));
                        var achatsOption = {
                            grid: {
                                left: "3%", // 左侧留白减少
                                right: "7%", // 右侧留白增加（为y轴标签腾出空间）
                                top: "12%", // 顶部留白
                                bottom: "10%", // 底部留白
                            },
                            tooltip: {
                                trigger: "axis",
                                formatter: function (params) {
                                    let res = params[0].name + '<br/>';
                                    params.forEach(item => {
                                        res += `${item.seriesName}: ${formatThousands(item.value)}<br/>`;
                                    });
                                    return res;
                                }
                            },
                            xAxis: {
                                type: "category",
                                data: achatscolumn,
                            },
                            yAxis: { type: "value" },
                            series: [
                                {
                                    name: __('Purchases_amount'),
                                    type: "line",
                                    data: achatsdata,
                                    smooth: true,
                                    lineStyle: {
                                        color: "#BFE787", // 主线条颜色
                                        width: 2,
                                    },
                                    areaStyle: {
                                        color: "#f0f9e8", // 区域填充色
                                    },
                                    // 关键修改：彻底禁用所有数据点标记
                                    symbol: "none",
                                    showSymbol: false,
                                    markPoint: { data: [] }, // 清空所有标记点
                                    itemStyle: { color: "transparent" }, // 确保无残留颜色
                                    label: { show: false }, // 禁用标签
                                },
                            ],
                        };

                        achatsChart.setOption(achatsOption);
                    } catch (err) {
                        console.error(err);
                    }
                }

                main();
                function getdata() {
                    return new Promise((resolve, reject) => {
                        $.ajax({
                            url: domain + "/kuerp/datainfo/index",
                            type: "post",
                            data: { types: 2 },
                            contentType: "application/x-www-form-urlencoded",
                            dataType: "json",
                            success: function (res) {
                                console.log(res, '33333333333333');
                                resolve({ column: res.column, data: res.data });
                            },
                            error: function (err) {
                                reject(err);
                            }
                        });
                    });
                }

                async function maina() {
                    try {
                        const res = await getdata();
                        console.log(res, '22222222222222');
                        const achatscolumn = res.column;
                        const achatsdata = res.data;
                        var helookedChart = echarts.init(
                            document.getElementById("helooked-chart")
                        );
                        //   折线图2
                        var helookedOption = {
                            grid: {
                                left: "3%", // 左侧留白减少
                                right: "7%", // 右侧留白增加（为y轴标签腾出空间）
                                top: "12%", // 顶部留白
                                bottom: "10%", // 底部留白
                            },
                            tooltip: {
                                trigger: "axis",
                                formatter: function (params) {
                                    let res = params[0].name + '<br/>';
                                    params.forEach(item => {
                                        res += `${item.seriesName}: ${formatThousands(item.value)}<br/>`;
                                    });
                                    return res;
                                }
                            },
                            xAxis: {
                                type: "category",
                                data: achatscolumn,
                            },
                            yAxis: { type: "value" },
                            series: [
                                {
                                    name: __('Sales_amount'),
                                    type: "line",
                                    data: achatsdata,
                                    smooth: true,
                                    lineStyle: {
                                        color: "#FFCC00", // 主线条颜色
                                        width: 2,
                                    },
                                    areaStyle: {
                                        color: "#FFFBDB", // 区域填充色
                                    },
                                    // 关键修改：彻底禁用所有数据点标记
                                    symbol: "none",
                                    showSymbol: false,
                                    markPoint: { data: [] }, // 清空所有标记点
                                    itemStyle: { color: "transparent" }, // 确保无残留颜色
                                    label: { show: false }, // 禁用标签
                                },
                            ],
                        };

                        helookedChart.setOption(helookedOption);
                    } catch (err) {
                        console.error(err);
                    }
                }

                maina();
                // 初始化 ECharts 实例
                function getentrepotsData() {
                    return new Promise((resolve, reject) => {
                        $.ajax({
                            url: domain + "/kuerp/datainfo/index",
                            type: "post",
                            data: { types: 3 },
                            contentType: "application/x-www-form-urlencoded",
                            dataType: "json",
                            success: function (res) {
                                const colorMap = new Map();
                                const datalist = res.data.map((item, index) => {
                                    let color;
                                    do {
                                        // 基于HSL色相生成不同颜色  
                                        color = '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);;
                                    } while (colorMap.has(color));

                                    colorMap.set(color, true);

                                    return {
                                        ...item,
                                        itemStyle: {
                                            color: color,
                                            borderWidth: 3
                                        }
                                    };
                                });
                                resolve({ data_: datalist });
                            },
                            error: function (err) {
                                reject(err);
                            }
                        });
                    });
                }
                async function entrepotsmain() {
                    try {
                        const res = await getentrepotsData();
                        const _data = res.data_;  // 修正这里：原代码是res.datalist，但实际应该是res.data_  

                        var entrepotsChart = echarts.init(document.getElementById("entrepots-chart"));

                        var pieOption = {
                            tooltip: {
                                trigger: "item",
                                 formatter: function(params) {
                                  return `${params.name}: 
                                    ${formatThousands(params.value)} 
                                    (${params.percent.toFixed(1)}%)`;
                                }
                            },
                            series: [
                                {
                                    name: __('Inventory_Statistics'),
                                    type: "pie",
                                    radius: ["0%", "80%"],
                                    center: ["50%", "50%"],
                                    roseType: "radius",
                                    avoidLabelOverlap: false,
                                    label: {
                                        show: false,
                                        position: "outside",
                                        fontSize: 16,
                                        formatter: "{b|{b}}\n{d}%",
                                        rich: {
                                            b: {
                                                fontSize: 14,
                                                lineHeight: 20
                                            }
                                        }
                                    },
                                    labelLine: {
                                        length: 10,
                                        length2: 20,
                                        smooth: true
                                    },
                                    // 修正2：使用正确的英文冒号  
                                    data: _data
                                }
                            ]
                        };

                        entrepotsChart.setOption(pieOption);

                    } catch (err) {
                        console.error(err);
                    }
                }


                entrepotsmain();
                // 初始化 ECharts 实例
                function getfondsData() {
                    return new Promise((resolve, reject) => {
                        $.ajax({
                            url: domain + "/kuerp/datainfo/index",
                            type: "post",
                            data: { types: 4 },
                            contentType: "application/x-www-form-urlencoded",
                            dataType: "json",
                            success: function (res) {
                                const colorMap = new Map();
                                const datalist = res.data.map((item, index) => {
                                    let color;
                                    do {
                                        // 基于HSL色相生成不同颜色  
                                        color = '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
                                    } while (colorMap.has(color));

                                    colorMap.set(color, true);

                                    return {
                                        ...item,
                                        itemStyle: {
                                            color: color,
                                            borderWidth: 3
                                        }
                                    };
                                });
                                resolve({ data_: datalist });
                            },
                            error: function (err) {
                                reject(err);
                            }
                        });
                    });
                }
                async function fondsmain() {
                    try {
                        const res = await getfondsData();
                        const _data = res.data_;  // 修正这里：原代码是res.datalist，但实际应该是res.data_  

                        var fondsChart = echarts.init(document.getElementById("fonds-chart"));

                        var pieOption = {
                            tooltip: {
                                trigger: "item",
                                 formatter: function(params) {
                                  return `${params.name}: 
                                    ${formatThousands(params.value)} 
                                    (${params.percent.toFixed(1)}%)`;
                                }
                            },
                            series: [
                                {
                                    name: __('Funds'),
                                    type: "pie",
                                    radius: ["0%", "80%"],
                                    center: ["50%", "50%"],
                                    roseType: "radius",
                                    avoidLabelOverlap: false,
                                    label: {
                                        show: false,
                                        position: "outside",
                                        fontSize: 16,
                                        formatter: "{b|{b}}\n{d}%",
                                        rich: {
                                            b: {
                                                fontSize: 14,
                                                lineHeight: 20
                                            }
                                        }
                                    },
                                    labelLine: {
                                        length: 10,
                                        length2: 20,
                                        smooth: true
                                    },
                                    // 修正2：使用正确的英文冒号  
                                    data: _data
                                }
                            ]
                        };

                        fondsChart.setOption(pieOption);

                    } catch (err) {
                        console.error(err);
                    }
                }


                fondsmain();




                function getTopdata() {
                    return new Promise((resolve, reject) => {
                        $.ajax({
                            url: domain + "/kuerp/datainfo/index",
                            type: "post",
                            data: { types: 5 },
                            contentType: "application/x-www-form-urlencoded",
                            dataType: "json",
                            success: function (res) {
                                console.log(res, '1111111111111111')
                                resolve(res);
                            },
                            error: function (err) {
                                reject(err);
                            }
                        });
                    });
                }
                async function getList() {
                    try {
                        const res = await getTopdata();
                        const respone = res;
                        var achatpie = echarts.init(document.getElementById("Achat-pie"));
                        var ventepie = echarts.init(document.getElementById("Vente-pie"));
                        var stockpie = echarts.init(document.getElementById("Stock-pie"));
                        var arrpie = echarts.init(document.getElementById("arr-pie"));
                        const purchaseNumElement = document.getElementById('purchase-num');
                        purchaseNumElement.textContent = respone.purchase_num;
                        const purchaseMonElement = document.getElementById('purchase-mon');
                        purchaseMonElement.textContent = formatThousands(respone.purchase_mon);
                        const SalesNumElement = document.getElementById('sales-num');
                        SalesNumElement.textContent = respone.sales_num;
                        const SalesMonElement = document.getElementById('sales-mon');
                        SalesMonElement.textContent = formatThousands(respone.sales_mon);
                        const StockNumElement = document.getElementById('stock-num');
                        StockNumElement.textContent = respone.stock_num;
                        const PurchaseMoneyElement = document.getElementById('purchase-money');
                        PurchaseMoneyElement.textContent = formatThousands(respone.purchase_money);
                        const CustomersMonElement = document.getElementById('customers-mon');
                        CustomersMonElement.textContent = formatThousands(respone.customers_mon);
                        const SuppliersMonElement = document.getElementById('suppliers-mon');
                        SuppliersMonElement.textContent = formatThousands(respone.suppliers_mon);
                        //本月买入饼图
                        var achatption = {
                            tooltip: {
                                trigger: "item",
                                position:"right",
                                formatter: function (params) {
                                    return `${params.name}: 
                                    ${formatThousands(params.value)} 
                                    (${params.percent.toFixed(1)}%)`;
                                }
                            },
                            series: [
                                {
                                    name: __('Data_Distribution'),
                                    type: "pie",
                                    radius: ["50%", "70%"],
                                    center: ["50%", "50%"],
                                    avoidLabelOverlap: false,
                                    itemStyle: {
                                        borderRadius: 4,
                                        borderColor: "#fff",
                                        borderWidth: 2,
                                    },
                                    label: {
                                        show: false,
                                    },
                                    emphasis: {
                                        scale: false,
                                        label: {
                                            show: false,
                                        },
                                    },
                                    labelLine: {
                                        show: false,
                                    },
                                    data: [
                                        {
                                            value: respone.purchase_num,
                                            name: __('Total_Purchases'),
                                            itemStyle: {
                                                color: "#3FC8E4",
                                            },
                                        },
                                        {
                                            value: respone.purchase_mon,
                                            name: __('Purchase_Amount_This_Month'),
                                            itemStyle: {
                                                
                                                color: "#FFCC00",
                                            },
                                        },
                                    ],
                                },
                            ],
                            // 已删除graphic部分（中心文字）
                            legend: {
                                show: false,
                            },
                        };

                        achatpie.setOption(achatption);
                        //饼图上方2
                        var venteption = {
                            tooltip: {
                                trigger: "item",
                                formatter: function (params) {
                                    return `${params.name}: 
                                    ${formatThousands(params.value)} 
                                    (${params.percent.toFixed(1)}%)`;
                                }
                            },
                            series: [
                                {
                                    name: __('Data_Distribution'),
                                    type: "pie",
                                    radius: ["50%", "70%"],
                                    center: ["50%", "50%"],
                                    avoidLabelOverlap: false,
                                    itemStyle: {
                                        borderRadius: 4,
                                        borderColor: "#fff",
                                        borderWidth: 2,
                                    },
                                    label: {
                                        show: false,
                                    },
                                    emphasis: {
                                        scale: false,
                                        label: {
                                            show: false,
                                        },
                                    },
                                    labelLine: {
                                        show: false,
                                    },
                                    data: [
                                        {
                                            value: respone.sales_num,
                                            name: __('Total_Sales_This_Month'),
                                            itemStyle: {
                                                color: "#3FC8E4",
                                            },
                                        },
                                        {
                                            value: respone.sales_mon,
                                            name: __('Sales_Amount_This_Month'),
                                            itemStyle: {
                                                
                                                color: "#FFCC00",
                                            },
                                        },
                                    ],
                                },
                            ],
                            // 已删除graphic部分（中心文字）
                            legend: {
                                show: false,
                            },
                        };

                        ventepie.setOption(venteption);

                        //饼图上方3
                        var stockoption = {
                            tooltip: {
                                trigger: "item",
                                formatter: function (params) {
                                    return `${params.name}: 
                                    ${formatThousands(params.value)} 
                                    (${params.percent.toFixed(1)}%)`;
                                }
                            },
                            series: [
                                {
                                    name: __('Data_Distribution'),
                                    type: "pie",
                                    radius: ["50%", "70%"],
                                    center: ["50%", "50%"],
                                    avoidLabelOverlap: false,
                                    itemStyle: {
                                        borderRadius: 4,
                                        borderColor: "#fff",
                                        borderWidth: 2,
                                    },
                                    label: {
                                        show: false,
                                    },
                                    emphasis: {
                                        scale: false,
                                        label: {
                                            show: false,
                                        },
                                    },
                                    labelLine: {
                                        show: false,
                                    },
                                    data: [
                                        {
                                            value: respone.stock_num,
                                            name: __('Total_Inventory'),
                                            itemStyle: {
                                                color: "#3FC8E4",
                                            },
                                        },
                                        {
                                            value: respone.purchase_money,
                                            name: __('Inventory_Cost'),
                                            itemStyle: {
                                                color: "#FFCC00",
                                       
                                            },
                                        },
                                    ],
                                },
                            ],
                            // 已删除graphic部分（中心文字）
                            legend: {
                                show: false,
                            },
                        };

                        stockpie.setOption(stockoption);


                        //饼图上方4
                        var arroption = {
                            tooltip: {
                                position:"top",
                                trigger: "item",
                                formatter: function (params) {
                                    return `${params.name}: 
                                    ${formatThousands(params.value)} 
                                    (${params.percent.toFixed(1)}%)`;
                                }
                            },
                            series: [
                                {
                                    name: __('Data_Distribution'),
                                    type: "pie",
                                    radius: ["50%", "70%"],
                                    center: ["50%", "50%"],
                                    avoidLabelOverlap: false,
                                    itemStyle: {
                                        borderRadius: 4,
                                        borderColor: "#fff",
                                        borderWidth: 2,
                                    },
                                    label: {
                                        show: false,
                                    },
                                    emphasis: {
                                        scale: false,
                                        label: {
                                            show: false,
                                        },
                                    },
                                    labelLine: {
                                        show: false,
                                    },
                                    data: [
                                        {
                                            value: respone.customers_mon,
                                            name: __('Customer_Debt'),
                                            itemStyle: {
                                                color: "#3FC8E4",
                                                
                                            },
                                        },
                                        {
                                            value: respone.suppliers_mon,
                                            name: __('Supplier_Debt'),
                                            itemStyle: {
                                                color: "#FFCC00",
                                            },
                                        },
                                    ],
                                },
                            ],
                            // 已删除graphic部分（中心文字）
                            legend: {
                                show: false,
                            },
                        };

                        arrpie.setOption(arroption);

                    } catch (err) {
                        console.error(err);
                    }
                }
                getList()


            });




        },
        datainfo: function () {
            var checkTime = function (i) {
                if (i < 10) {
                    i = "0" + i;
                }
                return i;
            };
            var showtime = function () {
                var nowdate = new Date();
                var h = nowdate.getHours(),
                    m = nowdate.getMinutes(),
                    s = nowdate.getSeconds(),
                    h = checkTime(h),
                    m = checkTime(m),
                    s = checkTime(s);
                return h + ":" + m + ":" + s;
            };
            var div = document.getElementById("showtime");
            setInterval(function () {
                div.innerHTML = showtime();
            }, 1000);  //反复执行函数

            //饼图
            function p_left2_chart(data, unit) {
                var p_left2_chart = Echarts.init(document.getElementById('p_left2_chart'), 'walden');
                var option = {
                    tooltip: {
                        trigger: "item",
                        formatter: "{b} : ({d}%)</br>销售额 : {c}" + unit,
                    },
                    legend: {
                        orient: 'horizontal',
                        left: 'center',
                        bottom: 'bottom',
                        textStyle: {
                            color: "#ffffff"
                        }
                    },
                    // color: ["#5AD8A6", "#5B8FF9", "#F6BD16", "#E8684A", "#00ec69"],
                    series: [
                        {
                            name: __('Sales_amount'),
                            type: 'pie',
                            radius: '50%',
                            data: data,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                p_left2_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_left2_chart.resize();
                });
            }
            //客户增长趋势
            function p_left3_chart(data, unit) {
                var p_left3_chart = Echarts.init(document.getElementById('p_left3_chart'), 'walden');
                var option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    // legend: {
                    //     data: ['客户总数','客户增长量']
                    // },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        splitLine: { show: false },
                        boundaryGap: true,
                        data: data.xAxis,
                        axisLabel: {
                            textStyle: {
                                color: '#AEBDFF'
                            }
                        }
                    },
                    yAxis: {
                        type: 'value',
                        splitLine: { show: false },
                        axisLabel: {
                            textStyle: {
                                color: '#AEBDFF'
                            }
                        }
                    },
                    series: [
                        {
                            name: __('Total_customers'),
                            type: 'line',
                            stack: __('Units'),
                            data: data.series.customers_num,
                            itemStyle: {
                                normal: {
                                    color: '#F62B2B', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#F62B2B' //改变折线颜色
                                    }
                                }
                            },
                        },
                        {
                            name: __('Customer_growth'),
                            type: 'line',
                            stack: __('Units'),
                            data: data.series.customers,
                            itemStyle: {
                                normal: {
                                    color: '#09F197', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#09F197' //改变折线颜色
                                    }
                                }
                            },
                        },
                    ]
                };
                p_left3_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_left3_chart.resize();
                });
            }

            function p_center1_chart(data, unit) {
                var p_center1_chart = Echarts.init(document.getElementById('p_center1_chart'), 'walden');
                option = {
                    // tooltip: {
                    //     trigger: 'axis'
                    // },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        },
                        formatter: function (params) {
                            let html = params[0].name + "<br>";
                            for (let i = 0; i < params.length; i++) {
                                html += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + params[i].color + ';"></span>'
                                if (params[i].seriesName == __('Sales_amount')) {
                                    html += params[i].seriesName + ":" + params[i].value + "" + unit + "<br>";
                                }
                                if (params[i].seriesName == __('Sales_count')) {
                                    html += params[i].seriesName + ":" + params[i].value + __('Units') + "<br>";
                                }
                            }
                            return html;
                        }
                    },
                    // legend: {
                    //     data: ['销售额', '销售笔数']
                    // },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        splitLine: { show: false },
                        boundaryGap: true,
                        data: data.xAxis,
                    },
                    yAxis: [
                        {
                            type: 'value',
                            name: unit,
                            //坐标轴最大值、最小值、强制设置数据的步长间隔
                            // interval: 1000,
                            axisLabel: {
                                //y轴上带的单位
                                formatter: '{value}'
                            },
                            //轴线
                            axisLine: {
                                show: true
                            },
                            //分割线
                            splitLine: {
                                show: false
                            }
                        },
                        {
                            type: 'value',
                            name: __('Units'),
                            axisLabel: {
                                formatter: '{value}'
                            },
                            //轴线
                            axisLine: {
                                show: true
                            },
                            //分割线
                            splitLine: {
                                show: false
                            }

                        }
                    ],
                    series: [
                        {
                            name: __('Sales_amount'),
                            type: 'line',
                            yAxisIndex: 0,
                            data: data.series.num,
                        }, {
                            name: __('Sales_count'),
                            type: 'line',
                            yAxisIndex: 1,
                            data: data.series.count,
                            itemStyle: {
                                normal: {
                                    color: '#09F197', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#09F197' //改变折线颜色
                                    }
                                }
                            },
                        }
                    ]
                };
                p_center1_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_center1_chart.resize();
                });
            }
            function p_center2_chart(data, unit) {
                var p_center2_chart = Echarts.init(document.getElementById('p_center2_chart'), 'walden');
                var option = {
                    // color : [ '#09F197', '#4e2b63' ],
                    // legend : [ {
                    //     itemWidth : 10,
                    //     itemHeight : 10,
                    //     align : 'left',
                    //     right : '45',
                    //     textStyle : {
                    //         fontSize : 10,
                    //         color : '#cccece',
                    //     },
                    //     itemStyle : {
                    //         borderColor : '#04a3a7',
                    //         borderWidth : 1
                    //     },
                    //
                    //     data : [ '采购' ]
                    // },
                    //     {
                    //         itemWidth : 10,
                    //         itemHeight : 10,
                    //         align : 'left',
                    //         right : 10,
                    //         textStyle : {
                    //             fontSize : 10,
                    //             color : '#cccece',
                    //         },
                    //         itemStyle : {
                    //             borderColor : '#b527ae',
                    //             borderWidth : 1
                    //         },
                    //
                    //         data : [ '销售' ]
                    //     },
                    // ],

                    grid: {
                        left: '15',
                        right: '15',
                        bottom: '5',
                        top: '20',
                        containLabel: true
                    },

                    xAxis: [
                        {
                            type: 'value',
                            // max : 100,
                            // min : -100,
                            splitLine: {
                                show: false
                            },
                            axisLine: {
                                show: true
                            },
                            axisTick: {
                                show: false
                            },
                            boundaryGap: ['5%', '5%'],
                            axisLabel: {
                                fontSize: 10,
                                color: '#AEBDFF',
                                show: true,
                                formatter: function (value, index) {
                                    var texts = [value, ''];

                                    if (value < 0) {
                                        texts = [-value, ''];
                                    }

                                    if (texts.join('') === '0') {
                                        return 0;
                                    }
                                    return texts.join('');
                                }
                            }
                        }
                    ],

                    yAxis: [
                        {
                            type: 'category',
                            splitLine: { show: false },
                            axisLine: {
                                show: true
                            },
                            axisTick: {
                                show: false
                            },
                            data: data.yAxis,
                            axisLabel: {
                                textStyle: {
                                    color: '#AEBDFF'
                                },
                            }
                        }
                    ],
                    series: [
                        //为了让两边的条形图在中间线分开设置的辅助数据
                        {
                            name: __('Auxiliary'),
                            type: 'bar',
                            stack: __('Total'),
                            itemStyle: {
                                normal: {
                                    barBorderColor: 'rgba(0,0,0,0)',
                                    color: 'rgba(0,0,0,0)'
                                }
                            },
                            data: [-1, -1, -1, -1, -1, -1]
                        },

                        {
                            name: __('Purchase'),
                            type: 'bar',
                            stack: __('Total'),
                            //barCategoryGap : '60%',
                            barWidth: 10,//柱图宽度
                            label: {
                                normal: {
                                    show: true,
                                    formatter: function (params) {
                                        var num = params.value;
                                        num = -num;
                                        return num;
                                    },
                                    position: 'left',
                                    color: '#cccece'
                                }
                            },
                            itemStyle: {
                                //通常情况下：
                                normal: {
                                    barBorderRadius: 20,
                                    color: new Echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                        offset: 0,
                                        color: '#099b58'
                                    }, {
                                        offset: 1,
                                        color: '#00FFC8'
                                    }]),
                                    shadowColor: 'rgba(0, 0, 0, 0.4)',
                                    shadowBlur: 20
                                },
                            },
                            data: data.series.purchase
                        },

                        {
                            name: __('Auxiliary'),
                            type: 'bar',
                            stack: __('Total'),
                            itemStyle: {
                                normal: {
                                    barBorderColor: 'rgba(0,0,0,0)',
                                    color: 'rgba(0,0,0,0)'
                                }
                            },
                            data: [1, 1, 1, 1, 1, 1]
                        },
                        {
                            name: __('Sales'),
                            type: 'bar',
                            stack: __('Total'),
                            barWidth: 10,//柱图宽度
                            label: {
                                normal: {
                                    show: true,
                                    formatter: function (params) {
                                        var num = params.value;
                                        return num;
                                    },
                                    position: 'right',
                                    color: '#cccece'
                                }
                            },
                            itemStyle: {
                                normal: {
                                    barBorderRadius: 20,
                                    color: new Echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                        offset: 0,
                                        color: '#13EFFA'
                                    }, {
                                        offset: 1,
                                        color: '#078a9b'
                                    }]),
                                    shadowColor: 'rgba(0, 0, 0, 0.4)',
                                    shadowBlur: 20
                                },
                            },
                            data: data.series.sales
                        }
                    ]
                };
                p_center2_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_center2_chart.resize();
                });
            }

            function p_right2_chart(data, unit) {
                var p_right2_chart = Echarts.init(document.getElementById('p_right2_chart'), 'walden');
                option = {
                    grid: {
                        left: '3%',
                        right: '10%',
                        bottom: '5%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        splitLine: { show: false },
                        axisLabel: { show: false },//坐标轴刻度标签
                        axisTick: { show: false },//坐标轴刻度
                        axisLine: { show: false },//坐标轴轴线
                    },
                    yAxis: {
                        type: 'category',
                        splitLine: { show: false },
                        axisTick: { show: false },
                        axisLine: { show: false },
                        axisLabel: {
                            color: '#fff',
                            fontSize: 14
                        },
                        data: data.yAxis
                    },
                    series: [
                        {
                            name: unit,//系列名称
                            type: 'bar',//柱状、条形图
                            barWidth: 19,//柱条的宽度,默认自适应
                            data: data.series.data,//系列中数据内容数组
                            label: { //图形上的文本标签
                                show: true,
                                // position: 'right',//标签的位置
                                // offset: [-60,1],  //标签文字的偏移，此处表示向上偏移40
                                formatter: '{c}{a}',//标签内容格式器 {a}-系列名,{b}-数据名,{c}-数据值
                                color: '#fff',//标签字体颜色
                                fontSize: 14  //标签字号
                            },
                            itemStyle: {//图形样式
                                normal: {
                                    barBorderRadius: 10,//柱条圆角半径,单位px.
                                    color: "#0272FC"
                                }
                            },
                            zlevel: 1
                        },
                        {
                            name: __('Progress_bar_background'),
                            type: 'bar',
                            barGap: '-100%',
                            barWidth: 19,
                            data: data.series.max,
                            color: '#1d359b',//柱条颜色
                            label: { //图形上的文本标签
                                show: true,
                                position: 'right',//标签的位置
                                // offset: [-40,0],  //标签文字的偏移，此处表示向上偏移40
                                // formatter: '{b}',//标签内容格式器 {a}-系列名,{b}-数据名,{c}-数据值
                                formatter: function (params) {
                                    return data.series.per[params.name] + '%';
                                },
                                color: '#fff',//标签字体颜色
                                fontSize: 14  //标签字号
                            },
                            itemStyle: {
                                normal: {
                                    barBorderRadius: 10
                                }
                            }
                        }
                    ]
                };
                p_right2_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_right2_chart.resize();
                });
            }

            getChart(1);
            function getChart(types) {
                $.ajax({
                    type: 'POST',
                    url: 'kuerp/datainfo/datainfo',
                    data: {
                        'types': types
                    },
                    success: function (res) {
                        var sales_money = res.sales_money;
                        var html = '';
                        $(sales_money).each(function (k, v) {
                            if (v === ',') {
                                html += '<small><span>,</span></small>';
                            } else {
                                html += '<span>' + v + '</span>';
                            }
                        });
                        $('#con_box').html(html);
                        $('.unit_value').html('（' + res.unit + '）');

                        p_left2_chart(res.left2_chart, res.unit);
                        p_left3_chart(res.left3_chart, res.unit);
                        p_center1_chart(res.center1_chart, res.unit);
                        p_center2_chart(res.center2_chart, res.unit);
                        p_right2_chart(res.right2_chart, res.unit);
                        var ht = '';
                        $(res.sale_list).each(function (k, v) {
                            var ks = k - (-1);
                            ht += '<tr><td><div class="sort_box"><span class="sort_number">' + ks + '</span></div></td><td>' + v.goods_code + '</td><td>' + v.goods_name + '</td><td>' + v.money_tax_price + '</td></tr>';
                        });
                        $('#phList').html(ht);
                    }
                });
            }
        },
        stockworing: function () {

            layui.use(['table', 'upload'], function () {
                var table = layui.table;

                var storesList = Config.storesList;
                var stores = xmSelect.render({
                    el: '#stores',
                    language: Config.lang == 'zh-cn' ? 'zn' : 'en',
                    tips: __('Serial'),
                    tips: __('Warehouse'),
                    data: storesList
                });

                var goodsList = Config.goodsList;
                var goodstype = xmSelect.render({
                    el: '#goods',
                    language: Config.lang == 'zh-cn' ? 'zn' : 'en',
                    tips: __('Serial'),
                    tips: __('Goods_category'),
                    data: goodsList
                });

                table.render({
                    elem: '#table'
                    , url: 'kuerp/datainfo/stockworing'
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "msg": '', //解析提示文本
                            "count": res.total, //解析数据长度
                            "data": res.rows //解析数据列表
                        };
                    }
                    , toolbar: '#thisToolbar' //开启头部工具栏，并为其绑定左侧模板
                    , defaultToolbar: [
                        { name: 'filter', title: __('Filter') }, // 列筛选
                        {
                            name: 'exports',
                            title: __('Exports'),
                            onClick: function (obj) {
                                // 获得数据并清除临时字段
                                var data = table.clearCacheKey(obj.data);
                                // 当前示例配置项
                                var options = obj.config;

                                if (data.length > 0 || Object.keys(data).length > 0) {
                                    table.exportFile(options.id, null, 'csv');
                                } else {
                                    layer.msg(__('No data'));
                                }

                            }
                        },
                        { name: 'print', title: __('Print') } // 打印
                    ]
                    , cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                    , text: { none: __('no data') } //默认：无数据。注：该属性为 layui 2.2.5 新增

                    , cols: [[
                        {
                            field: 'goods_type_id', title: __('goods_type'), templet: function (d) {
                                if (d.goodstype.supplier_type_name != undefined) {
                                    return d.goodstype.supplier_type_name;
                                } else {
                                    return '';
                                }
                            }
                        },
                        { field: 'goods_code', title: __('goods_code') },
                        { field: 'goods_name', title: __('goods_name') },
                        { field: 'goods_barcode', title: __('goods_barcode') },
                        {
                            field: 'goods_image', title: __('goods_image'), operate: false, templet: function (d) {
                                return "<a href='javascript:;'><img src=" + d.goods_image + "></a>";
                            }
                        },
                        {
                            field: 'unit', title: __('unit'), templet: function (d) {
                                if (d.more_unit == 1) {
                                    return d.unitconversion;
                                }
                                if (d.more_unit == 2) {
                                    return d.unit.name;
                                }
                            }
                        },
                        {
                            field: 'stores', title: __('stores'), templet: function (d) {
                                if (d.stores.name != undefined) {
                                    return d.stores.name;
                                } else {
                                    return '';
                                }
                            }
                        },
                        { field: 'min_stock', title: __('min_stock') },
                        { field: 'max_stock', title: __('max_stock') },
                        { field: 'stock', title: __('current_stock') },
                    ]]
                });

                //头工具栏事件
                table.on('toolbar(table)', function (obj) {
                    switch (obj.event) {
                        case 'refresh':
                            table.reload('table', []);
                            break;
                    }
                });
                //搜索事件
                $('#search').on('click', function () {
                    table.reload('table', {
                        where: {
                            filter: JSON.stringify(getSearch()),
                            op: JSON.stringify(getOp()),
                        }
                        , page: {
                            curr: 1,
                            prev: __('Previous'),
                            next: __('Next'),
                            first: __('First'),
                            last: __('Last'),
                            skipText: [__('Go to page'), '', __('Confirm')],
                            countText: [__('Total') + ' ', ' ' + __('Records')],
                            limitTemplet: function (item) {
                                return item + ' ' + __('entries');
                            }
                        }
                    });
                });
                function getSearch() {
                    var search = {};

                    var storesArr = stores.getValue();
                    var stores_id = '';
                    if (storesArr.length > 0) {
                        $(storesArr).each(function (k, v) {
                            if (stores_id === '') {
                                stores_id += v.value;
                            } else {
                                stores_id += ',' + v.value;
                            }
                        })
                    }
                    search.stores_id = stores_id;

                    var typeArr = goodstype.getValue();
                    var type_id = '';
                    if (typeArr.length > 0) {
                        $(typeArr).each(function (k, v) {
                            if (type_id === '') {
                                type_id += v.value;
                            } else {
                                type_id += ',' + v.value;
                            }
                        })
                    }
                    search.type_id = type_id;

                    var goods_code = $('#goods_code').val();
                    if (goods_code != '') {
                        search.goods_code = goods_code;
                    }
                    var goods_name = $('#goods_name').val();
                    if (goods_name != '') {
                        search.goods_name = goods_name;
                    }
                    return search;
                }
                function getOp() {
                    var op = {};
                    op.goods_code = 'LIKE';
                    op.goods_name = 'LIKE';
                    return op;
                }
            });
        },
    };

    return Controller;
});
